package day6;

import java.util.ArrayList;
import java.util.Random;

//用大集合存入随机的20个1-100间的数，筛选其中偶数到小集合中，要求用自定义方法实现筛选
public class ArrayListSelect {
    public static void main(String[] args) {
        ArrayList<Integer> bigList = new ArrayList<>();
        for (int i = 0; i < 20; i++) {
            Random a = new Random();
            int num = a.nextInt(100) + 1;
            bigList.add(num);
        }
        ArrayList<Integer> smallList = getSmallList(bigList);
        for (int i = 0; i < smallList.size(); i++) {
            System.out.println(smallList.get(i));

        }
        System.out.println("共有偶数多少个：" + smallList.size());
    }

    public static ArrayList<Integer> getSmallList(ArrayList<Integer> bigList) {
        ArrayList<Integer> smallList = new ArrayList<>();
        for (int i = 0; i < bigList.size(); i++) {
            int b = bigList.get(i);
            if (b % 2 == 0) {
                smallList.add(b);
            }
        }
        return smallList;
    }
}
